// 输入弹框
const componentBehaviors = require('../../../../behaviors/component');
import { COMPONENT_OPTIONS } from '../../../../constants/common';
import { getExpressCompanyList } from '../../../../api/common';

Component({
    behaviors: [componentBehaviors],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        title: {
            type: String,
            value: '标题',
        },
        show: {
            type: Boolean,
            value: false,
        },
        defaultValue: {
            type: String,
            value: '',
        },
    },

    observers: {
        'show, defaultValue': function (flag, val) {
            flag && this.setData({
                inputValue: val,
            });
        },
    },
    data: {
        showExpress: false,
        inputValue: '',
        express: null,
        expressList: [],
    },
    methods: {
        numberInputAction: function (event) {
            const { value } = event.detail;
            this.setData({
                inputValue: value,
            });
        },
        openSelectExpress: async function () {
            const expressList = await getExpressCompanyList();
            console.log('ExpressInputModal => 获取到的快递列表为', expressList);
            this.setData({
                expressList,
                showExpress: true,
            });
        },
        // 选择快递公司
        expressChange: function (event) {
            console.log('ExpressInputModal => 快递公司选择结果', event);
            this.setData({
                express: event.detail,
            });
        },
        // 确认
        onConfirm: function () {
            const { express, inputValue } = this.data;
            this.triggerEvent('ok', {
                platform: express ? express.id : '',
                number: inputValue,
            })
        },
        // 取消
        onClose: function (e) {
            this.triggerEvent('close', e.detail)
        },
    }
})